package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    public void work(BookList bookList){
        System.out.println("新增图书....");
        int currentsize= bookList.getUseSize();
        if(currentsize==bookList.getBooks().length){
            System.out.println("书架已经满了");
        }
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你想添加的书籍：");
        String name=scanner.nextLine();
        System.out.println("请输入书的作者：");
        String author=scanner.nextLine();
        System.out.println("请输入书的类型：");
        String type=scanner.nextLine();
        System.out.println("请输入书的价格：");
        int price=scanner.nextInt();

        Book newbook=new Book(name,author,price,type);
        for (int c = 0; c < currentsize; c++) {
            Book book=bookList.getBooks(c);
            if(book.getName().equals(name)){
                System.out.println("有这本书");
               return;
            }
        }
        bookList.setBooks(currentsize,newbook);
        bookList.setUseSize(currentsize+1);
        System.out.println("新增图书成功！！！");
    }
}
